<div class="mask-box">
  <%= form_for(@order, url: admin_orders_path) do |f| %>
    <div class="mask-head">
      <h4>售卖</h4>
      <span></span>
    </div>
    <div class="mask-con">
      <div class="mask-marc">
        <ul class="purch-b clearfix">
          <li>
            <span>购买人:</span>
            <div class="m-purch">
              <%= f.hidden_field :good_id, value: @good.id %>
              <%= f.radio_button :order_type, "学员购买", class: "p-radio", checked: "checked" %>
              <div class="ra-btn ra-checked">
                <span></span>
              </div>
              <b>学员购买</b>
              <div class="n-purch">
                <%= f.radio_button :order_type, "意向学员购买", class: "p-radio" %>
                <div class="ra-btn dis-s">
                  <span></span>
                </div>
                <span>意向学员购买</span>
              </div>
              <div class="c-nost">
                <%= f.radio_button :order_type, "非学员购买", class: "p-radio" %>
                <div class="ra-btn no-st">
                  <span></span>
                </div>
                <span>非学员购买</span>
              </div>
            </div>
          </li>
          <li id="cho-stud">
            <%= f.text_field :student_id, id: "choStu"%>
            <span>选择学员:</span>
            <div class="single-box intention">
              <div class="single-downbtn">
                <span>全部学员</span>
                <em></em>
              </div>
              <div class="single-dropdown">
                <em></em>
                <input type="text" placeholder="搜索">
                <ul>
                  <% @students.each do |student| %>
                    <li data_id="<%= student.id %>" ><%= student.name %>-<%= student.mobile %></li>
                  <% end %>
                </ul>
              </div>
            </div>
            <div class="single-box n-intention">
              <div class="single-downbtn">
                <span>全部意向学员</span>
                <em></em>
              </div>
              <div class="single-dropdown">
                <em></em>
                <input type="text" placeholder="搜索">
                <ul>
                  <% @potential_students.each do |potential| %>
                    <li data_id="<%= potential.id %>" ><%= potential.name %>-<%= potential.mobile %></li>
                  <% end %>
                </ul>
              </div>
            </div>
          </li>
          <li>
            <span>商品数量:</span>
            <%#<input class="purch-num" type="text" placeholder="1" onkeyup="intNum(this)">%>
            <%= f.text_field :amount, class: "purch-num", value: "1", onkeyup: "intNum(this)" %>
          </li>
          库存:<%= @good.stock.present? ? @good.stock : '-' %>
        </ul>
        <ul class="clearfix" id="good_price">
          <li>
            <span>商品名:</span>
            <em><%= @good.name %></em>
          </li>
          <li>
            <span>单价:</span>
            <input type="text" name="order[real_price]" id="real_price" value="<%= @good.time_discount_price %>">
            <em><%= @good.time_discount_price %>元</em>
            <b class="original-cost"><%= @good.price %>元</b>
          </li>
          <li>
            <span>合计:</span>
            <input type="text" name="order[total_price]" id="total_price" value="<%= @good.time_discount_price %>">
            <em><%= @good.time_discount_price %>元</em>
          </li>
        </ul>
      </div>
    </div>
    <div class="ad-stud">
      <span>还不是学员？</span>
      <a href="/admin/potential_students/new">添加学员</a>
    </div>
    <div class="mask-confirm">确认购买</div>
    <%= f.submit "确认购买", class: "mask-confirm" %>
  <% end %>
</div>


<script src="/assets/js/common.js"></script>
<script>
if ($("#comsh").text() == "课程商品") {
  $(".c-nost").css({
    "display" : "none"
  })
};
$(".purch-num").change(function() {
  console.log($(this).val());
  var unit = $(this).val();
    $.ajax({
      type:'get', url:"/admin/goods/" + <%= @good.id %> + "/price?unit=" + unit,
      success: function(data) {
        if (data.error) {
        }
      }
    });
})
// 控制radio按钮
$(".purch-b .ra-btn").on("click", function() {
  $(this).prev().attr("checked", "checked");
})
// 可放 common.js
$(".mask .ra-btn").on("click", function() {
  $(".mask .ra-btn").removeClass("ra-checked");
  $(this).addClass("ra-checked");
  $(this).prev("input").prop("checked", true);
  if ($(this).hasClass("no-st")) {
    $("#cho-stud").css({
      "display" : "none"
    });
  } else {
    $("#cho-stud").css({
      "display" : "block"
    });
    if ($(this).hasClass("dis-s")) {
      $("#cho-stud .intention").css({
        "display" : "none"
      });
      $("#cho-stud .n-intention").css({
        "display" : "block"
      });
    } else {
      $("#cho-stud .intention").css({
        "display" : "block"
      });
      $("#cho-stud .n-intention").css({
        "display" : "none"
      });
    }
  }
});
$("#sale").on("click", function() {
  $(".mask").css({
    "display" : "block"
  });
  $(".mask-box").css({
    "margin-top" : -($(".mask-box").height() + parseInt($(".mask-box").css("padding-bottom")))/2
  })
})
// 弹窗(有重复则删除)
$(".mask-head span").on("click", function() {
  $(this).parent().parent().find("input").val("");
  $(".mask").css({
    "display" : "none"
  })
})
$(".mask-confirm").on("click", function() {
  $(".mask").css({
    "display" : "none"
  })
})
/* 单选下拉列表 */
$(".purch-b .single-downbtn").on("click", function() {
  if ($(this).next(".single-dropdown").hasClass("menuopen")) {
    $(this).next(".single-dropdown").removeClass("menuopen");
  } else {
    $(this).next(".single-dropdown").addClass("menuopen");
    $(this).parent().hover(function() {

    }, function() {
      $(this).children(".single-dropdown").removeClass("menuopen");
    });
    $(".purch-b .single-box li").on("click", function() {
      $(this).parent().parent().removeClass("menuopen");
      $(this).parent().parent().parent().find("span").text($(this).text());
      $(this).parent().parent().find("input").val("");
      $(".purch-b .single-dropdown li").removeClass("mul-hide");
      $("#choStu").val($(this).attr("data_id"));
      console.log($(this).attr("data_id"));
      return;
    });

    $(this).next("div").find("input").on('input',function(){
      console.log($(this));
      if ($(this).val() != "") {
          console.log($(this).val());
          $(".purch-b .single-dropdown li").addClass("mul-hide");
          console.log($($(".single-dropdown li:contains(" + $(this).val() + ")")).removeClass("mul-hide"));
      } else {
        $(".purch-b .single-dropdown li").removeClass("mul-hide");
      }
    })
  }
});
</script>
